﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="KhoaLuan.Account.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link href="/Style/modal.css" rel="stylesheet" />
    <link href="/Style/bootstrap.min.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="/Style/font-awesome.min.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="/Style/smartadmin-production.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="/Style/smartadmin-skins.css" rel="stylesheet" type="text/css" media="screen" />
    <link href="/Style/demo.css" rel="stylesheet" type="text/css" media="screen" />
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,300,400,700" />

</head>
<body id="login" class="animated fadeInDown">
    <header id="header">
        <div style="font-weight: bold; font-size: 30px; float: left; width: 500px !important; margin-top: 10px;">
            HỆ THỐNG QUẢN LÝ
        </div>
        <span id="login-header-space"><span class="hidden-mobile">Cần tài khoản?</span> <a href="register.html" class="btn btn-danger">Tạo tài khoản</a> </span>

    </header>

    <div style="width: 100%;">
        <div style="width: 500px; margin: 0 auto !important;">
            <div class="well no-padding">
                <form id="loginform" runat="server" class="smart-form client-form">

                    <header>
                        Đăng  Nhập Hệ Thống						
                    </header>

                    <fieldset>
                        <section>
                            <label class="label">Tổ chức</label>
                            <asp:DropDownList runat="server" ID="cbOrg" CssClass="select2"></asp:DropDownList>
                        </section>
                        <section>
                            <label class="label">Tài khoản</label>
                            <label class="input">
                                <i class="icon-append fa fa-user"></i>
                                <input type="text" name="username" id="txtUserName" />
                                <b class="tooltip tooltip-top-right"><i class="fa fa-user txt-color-teal"></i>Nhập tài khoản vào đây</b></label>
                        </section>

                        <section>
                            <label class="label">Password</label>
                            <label class="input">
                                <i class="icon-append fa fa-lock"></i>
                                <input type="password" name="password" id="txtPassword" />
                                <b class="tooltip tooltip-top-right"><i class="fa fa-lock txt-color-teal"></i>Nhập mật khẩu vào đây</b>
                            </label>
                            <div class="note">
                                <a href="/Account/ForgotPassword.aspx">Quên mật khẩu?</a>
                            </div>
                        </section>

                        <section>
                            <label class="checkbox">
                                <input type="checkbox" name="remember" checked="" id="chbRemember" />
                                <i></i>Ghi Nhớ Đăng Nhập</label>
                            <div id="divErrorMes">
                            </div>
                        </section>
                    </fieldset>
                    <footer>
                        <input type="button" class="btn btn-primary" id="btnLogin" value="Đăng nhập" />
                    </footer>
                </form>

            </div>
        </div>
    </div>

    <script src="/Scripts/libs/jquery-2.0.2.min.js"></script>
    <script src="/Scripts/libs/jquery-ui-1.10.3.min.js"></script>
    <script src="/Scripts/plugin/select2/select2.js"></script>
    <script src="/Scripts/bootstrap/bootstrap.min.js"></script>
    <script src="/Scripts/plugin/jquery-validate/jquery.validate.min.js"></script>
    <script src="/Scripts/app.js"></script>
    <script src="/Scripts/dluscript.js"></script>
    <script type="text/javascript">
        runAllForms();
        function ShowErrorMes(mes) {
            var divmess = $('<div class="alert alert-danger fade in">');
            divmess.append($('<button class="close" data-dismiss="alert">').text('x')).append($('<i class="fa-fw fa fa-times">')).append(mes);
            $('#divErrorMes').empty().append(divmess);
        }

        $(document).ready(function () {
            $(function () {
                // Validation
                $("#loginform").validate({
                    // Rules for form validation
                    rules: {
                        username: {
                            required: true
                        },
                        password: {
                            required: true
                        }
                    },

                    // Messages for form validation
                    messages: {
                        username: {
                            required: 'Vui long nhap ten dang nhap'
                        },
                        password: {
                            required: 'Vui long nhap mat khau'
                        }
                    },

                    // Do not change code below
                    errorPlacement: function (error, element) {
                        error.insertAfter(element.parent());
                    }
                });
            });
            $("#btnLogin").click(function () {
                var orgid = $("#<%=cbOrg.ClientID%>").val();
                if (orgid == "") {
                    alertbox("Vui lòng chọn tổ chức");
                    return;
                }
                if (!$("#loginform").valid())
                    return;
                CallAjaxAspx("POST", "LoginSystem", "Login.aspx",
                                {
                                    orgid: parseInt(orgid),
                                    username: $("#txtUserName").val(),
                                    password: $("#txtPassword").val(),
                                    remember: $("#chbRemember").attr("checked") == "checked",
                                }, function (response) {
                                    var obj = JSON.parse(response);
                                    if (obj.Status) {
                                        var url = GetQueryString("returnUrl");
                                        if (url != null)
                                            document.location.href = url;
                                        else
                                            document.location.href = "/MainSys/Manager/Admin.aspx";
                                    }
                                    else {
                                        ShowErrorMes('Tài khoản hoặc mật khẩu không chính xác');
                                    }
                                }, function () {
                                    debugger;
                                    $("body").addClass("loading");
                                }, function () {
                                    debugger;
                                    $("body").removeClass("loading");
                                });
            });
        });
        function GetQueryString(name) {
            name = name.toLowerCase();
            var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search.toLowerCase());
            return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
        }
    </script>
    <div class="modal"></div>
</body>

</html>
